/*
 * @Author: your name
 * @Date: 2021-03-06 13:45:28
 * @LastEditTime: 2021-04-13 01:57:39
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \xgwsp_frontendd:\project\tsx\demo-tsx\src\hooks\usePagination.ts
 */
import { reactive, ref } from 'vue';
interface IPagination {
  pageSizeOptions: string[];
  showSizeChanger: boolean;
  total: number;
  showTotal: Function;
  current?: number;
  pageSize?: number;
}

export const globalPagination = (api: any) => {
  const data = ref<any[]>([]);
  const pagination = reactive<IPagination>({
    pageSizeOptions: ['10', '50', '100', '200', '500'],
    showSizeChanger: true,
    total: 0,
    showTotal: (total: number): string => {
      return `${total}条`;
    },
  });

  const queryList = async (params: any) => {
    const { datas, total } = await api(params);
    data.value = datas;
    pagination.total = total;
  };
  return {
    data,
    pagination,
    queryList,
  };
};
